<?php

class FoodStorageValidator extends Illuminate\Validation\Validator
{

    protected $implicitRules = array('Required', 'RequiredWith', 'RequiredWithout', 'RequiredIf', 'Accepted', 'RequiredWithoutField');
    
    public function __construct(\Symfony\Component\Translation\TranslatorInterface $translator, $data, $rules, $messages = array())
    {
        parent::__construct($translator, $data, $rules, $messages);
        $this->isImplicit('fail');
    }
    
    public function validateIngroup($attribute, $value, $parameters = null)
    {
        $class_name = $parameters[0];
        $group_id = Auth::user()->group_id;
        return $class_name::find($value)->where('group_id', '=', $group_id)->count();
    }

    public function validateUniqueingroup($attribute, $value, $parameters = null)
    {
        $class_name = $parameters[0];
        $group_id = Auth::user()->group_id;
        return !(
            $class_name::where('group_id', '=', $group_id)
            ->where($attribute, '=', $value)
            ->count()
        );
    }

    public function validateItemnumbervalid($attribute, $value, $paramaters = null)
    {
        $group_id = Auth::user()->group_id;
        return Item::where('group_id', '=', $group_id)
            ->where('item_number', '=', $value)
            ->count();
        
    }

    public function validateItemnumberinstock($attribute, $value, $paramaters = null)
    {
        return Item::where('status', '=', 'in stock')
            ->where('item_number', '=', $value)
            ->count();
   
        
    }
}